import 'dart:convert' show json;

import 'package:mahjong/entity/AbstractFormart.dart';

T asT<T>(dynamic value) {
  if (value is T) {
    return value;
  }
  return null;
}

class MetaRoomEntity implements AbstractFormart {
  MetaRoomEntity({
    this.allUserInfo,
    this.roomType,
    this.roomRule,
    this.code,
  });

  factory MetaRoomEntity.fromJson(Map<String, dynamic> jsonRes) =>
      jsonRes == null
          ? null
          : MetaRoomEntity(
              allUserInfo: asT<Object>(jsonRes['allUserInfo']),
              roomType: asT<String>(jsonRes['roomType']),
              roomRule: asT<String>(jsonRes['roomRule']),
              code: asT<String>(jsonRes['code']),
            );

  Object allUserInfo;
  String roomType;
  String roomRule;
  String code;

  Map<String, dynamic> toJson() => <String, dynamic>{
        'allUserInfo': allUserInfo,
        'roomType': roomType,
        'roomRule': roomRule,
        'code': code,
      };

  @override
  String toString() {
    return json.encode(this);
  }

  @override
  MetaRoomEntity caseToEntity(Map<String, dynamic> jsonRes) =>
      MetaRoomEntity.fromJson(jsonRes);
}
